package com.example.electricbicycle.service;

import com.example.electricbicycle.dao.AfterSalesAdminDAO;
import com.example.electricbicycle.dao.AfterSalesAdminDAOImpl;
import com.example.electricbicycle.po.AfterSalesAdmin;

import java.util.List;

public class AfterSalesAdminServiceImpl implements AfterSalesAdminService {

    // 依赖 DAO 层
    private final AfterSalesAdminDAO afterSalesDAO = new AfterSalesAdminDAOImpl();

    @Override
    public List<AfterSalesAdmin> getAllAfterSales() {
        // 直接调用 DAO 层方法
        return afterSalesDAO.getAllAfterSales();
    }

    @Override
    public AfterSalesAdmin getAfterSalesById(int id) {
        // 业务逻辑校验（可选）
        if (id <= 0) {
            throw new IllegalArgumentException("售后订单ID无效");
        }
        return afterSalesDAO.getAfterSalesById(id);
    }

    @Override
    public boolean addAfterSales(AfterSalesAdmin afterSales) {
        // 业务逻辑校验
        if (afterSales == null) {
            throw new IllegalArgumentException("售后订单对象不能为空");
        }
        if (afterSales.getSaleOrderId() == null || afterSales.getUserId() == null) {
            throw new IllegalArgumentException("关联订单ID和用户ID不能为空");
        }
        if (afterSales.getProblem() == null || afterSales.getProblem().trim().isEmpty()) {
            throw new IllegalArgumentException("问题描述不能为空");
        }
        // 调用 DAO 层方法
        return afterSalesDAO.addAfterSales(afterSales);
    }

    @Override
    public boolean updateAfterSales(AfterSalesAdmin afterSales) {
        // 业务逻辑校验
        if (afterSales == null || afterSales.getId() == null) {
            throw new IllegalArgumentException("售后订单ID不能为空");
        }
        // 调用 DAO 层方法
        return afterSalesDAO.updateAfterSales(afterSales);
    }

    @Override
    public boolean deleteAfterSales(int id) {
        // 业务逻辑校验
        if (id <= 0) {
            throw new IllegalArgumentException("售后订单ID无效");
        }
        // 调用 DAO 层方法
        return afterSalesDAO.deleteAfterSales(id);
    }
}